package rd.hardcore.ui.config.nav 
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.events.TextEvent;
	import flash.text.TextExtent;
	import fr.digitas.flowearth.conf.Conf;
	import rd.hardcore.ui.config.ConfigPanel;
	import rd.hardcore.ui.config.content.ConfigPanelContent;
	
	/**
	 * ...
	 * @author Romain
	 */
	public class Nav extends Nav_FC
	{
		private var container : Sprite;
		
		private var current : NavItem;
		private var old		: NavItem;
		
		public function Nav() 
		{
			container = new Sprite();
			addChild(container);
			
			mouseEnabled = false;
			
			container.y = 20;
			container.x = 20;
		}
		
		public function build() : void
		{
			var i : int = 0;
			
			var xml : XML = Conf.getDatas("config");
			
			for each( var node : XML in xml.children() )
			{
				var item : NavItem = new NavItem();
				item.build(node);
				container.addChild(item);
				
				item.y = i * 25;
				
				if ( node.@default.length() > 0)
				{
					current = old= item;
					current.select();
				}
					
				i++;
			}
			
			addEventListener(MouseEvent.CLICK, handleClick);
		}
		
		private function handleClick(e:MouseEvent):void 
		{			
			if ( !(e.target is NavItem) ) return;
			
			if (ConfigPanelContent.isTweening) return;
			ConfigPanelContent.isTweening = true;
			
			if (old) old.unselect();
			
			current = e.target as NavItem;
			current.select();
			
			old = current;
			
			dispatchEvent(new TextEvent(ConfigPanel.UPDATE,true, false, current.ID));
		}
		
	}

}